home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / sozo2 / scsrc20.lzh / LD.LZH / MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-01  |  3.3 KB  |  224 lines

  1.  
  2. /*
  3.  * Copyright (c) 1991 by Sozobon, Limited.  Author: Johann Ruegg
  4.  *
  5.  * Permission is granted to anyone to use this software for any purpose
  6.  * on any computer system, and to redistribute it freely, with the
  7.  * following restrictions:
  8.  * 1) No charge may be made other than reasonable charges for reproduction.
  9.  * 2) Modified versions must be clearly marked as such.
  10.  * 3) The authors are not responsible for any harmful consequences
  11.  *    of using this software, even if they result from defects in it.
  12.  */
  13.  
  14. static char Version[] = "ld version 2.0  Copyright (c) 1991 Sozobon Ltd";
  15.  
  16. #include <stdio.h>
  17.  
  18. int mflag, vflag, symout;
  19. int only8;
  20. char *tmpdir;
  21. char *oname;
  22.  
  23. #ifdef MINIX
  24. long mstack, atol();
  25. #endif
  26.  
  27. #ifdef TOS
  28. #define FSEP    '\\'
  29. #else
  30. #define FSEP    '/'
  31. #endif
  32.  
  33. int tb, db, trelb, drelb, orelb;
  34.  
  35. main(argc, argv)
  36. char **argv;
  37. {
  38.     int i;
  39.     char *getenv();
  40.  
  41.     setbuf(stdout, NULL);
  42.     if ((tmpdir = getenv("TMP")) == NULL)
  43. #ifdef TOS
  44.         tmpdir = "\\";
  45. #else
  46.         tmpdir = "/tmp/";
  47. #endif
  48.  
  49.     for (i=1; i<argc; i++)
  50.         switch (argv[i][0]) {
  51.         case '-':
  52.             if (doopt(&argv[i][1], argv[i+1], 0))
  53.                 i++;
  54.             break;
  55. #ifdef TOS
  56.         case '+':
  57.             if (doopt(&argv[i][1], argv[i+1], 1))
  58.                 i++;
  59.             break;
  60. #endif
  61. #ifdef MINIX
  62.         case '=':
  63.             mstack = atol(&argv[i][1]);
  64.             break;
  65. #endif
  66.         default:
  67.             opentmps();
  68.             pass1(argv[i]);
  69.             break;
  70.         }
  71.  
  72.     pass2();
  73.     t_exit();
  74.     exit(0);
  75. }
  76.  
  77. opentmps()
  78. {
  79.     static int didit = 0;
  80.     int pid;
  81.     char pname[20];
  82.  
  83.     if (didit)
  84.         return;
  85.     didit = 1;
  86.     pid = getpid();
  87.     sprintf(pname, "a%d", pid);
  88.     tb = opent(pname);
  89.     pname[0] = 'b';
  90.     db = opent(pname);
  91.     pname[0] = 'c';
  92.     trelb = opent(pname);
  93.     pname[0] = 'd';
  94.     drelb = opent(pname);
  95.     pname[0] = 'e';
  96.     orelb = opent(pname);
  97. }
  98.  
  99. opent(s)
  100. char *s;
  101. {
  102.     int dlen, flen;
  103.     char *bp, *mmalloc();
  104.     int needsep;
  105.  
  106.     dlen = strlen(tmpdir);
  107.     if (tmpdir[dlen-1] != FSEP) {
  108.         needsep = 1;
  109.     } else
  110.         needsep = 0;
  111.     flen = strlen(s);
  112.     bp = mmalloc(dlen+flen+needsep+1);
  113.     strcpy(bp, tmpdir);
  114.     bp += dlen;
  115.     if (needsep)
  116.         *bp++ = FSEP;
  117.     strcpy(bp, s);
  118.     return t_open(bp);
  119. }
  120.  
  121. doopt(s, next, lflag)
  122. char *s, *next;
  123. {
  124.     int i;
  125.  
  126. #ifdef TOS
  127.     if (lflag)
  128.         lower(s);
  129. #endif
  130.     while (*s) {
  131.         switch (*s) {
  132.         case 'm':
  133.             mflag++;
  134.             break;
  135.         case 'v':
  136.             vflag++;
  137.             break;
  138.         case 't':
  139.             symout++;
  140.             break;
  141.         case 'p':
  142.         case 'b':
  143.             /* archaic */
  144.             break;
  145.         case 'V':
  146.             fprintf(stderr, "%s\n", Version);
  147.             break;
  148.         case 'f':
  149.             fpass(next);
  150.             return 1;
  151.         case 'u':
  152.             sundeff(next);
  153.             return 1;
  154.         case 'o':
  155.             oname = next;
  156.             return 1;
  157.         case '8':
  158.             only8 = 1;
  159.             break;
  160.         }
  161.         s++;
  162.     }
  163.     return 0;
  164. }
  165.  
  166. fpass(s)
  167. char *s;
  168. {
  169.     FILE *fd;
  170.     char buf[81];
  171.  
  172.     opentmps();
  173.     fd = fopen(s, "r");
  174.     if (fd == NULL) {
  175.         fprintf(stderr, "Cant open %s\n", s);
  176.         exit(1);
  177.     }
  178.     while (fscanf(fd, "%80s", buf) == 1) {
  179.         pass1(buf);
  180.     }
  181.     fclose(fd);
  182. }
  183.  
  184. fatal(s)
  185. char *s;
  186. {
  187.     fprintf(stderr, "error: %s\n", s);
  188.     t_exit();
  189.     exit(1);
  190. }
  191.  
  192. fatals(s, t)
  193. char *s, *t;
  194. {
  195.     fprintf(stderr, "error: %s %s\n", s, t);
  196.     t_exit();
  197.     exit(1);
  198. }
  199.  
  200. warns(s, t)
  201. char *s, *t;
  202. {
  203.     fprintf(stderr, "warning: %s %s\n", s, t);
  204. }
  205.  
  206. #ifdef TOS
  207. lower(s)
  208. char *s;
  209. {
  210.     char c;
  211.  
  212.     while (*s) {
  213.         c = *s;
  214.         if (c >= 'A' && c <= 'Z') {
  215.             c -= 'A';
  216.             c += 'a';
  217.         }
  218.         *s = c;
  219.         s++;
  220.     }
  221. }
  222. #endif
  223.  
  224.